public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
//        for (int i = 0; i < 20; i++) {
//            int tmp = i;
//            Thread thread = new Thread(() -> {
//                System.out.print(tmp+" ");
//            });
//            thread.start();
//            thread.join();
//        }
//
//        System.out.println("ok");

        Thread[] threads = new Thread[20];
        for(int i=0; i<20; i++){
            final int n = i;
            threads[i] = new Thread(new Runnable() {
                @Override
                public void run() {//内部类使用外部的变量，必须是final修饰
                    System.out.println(n);
                }
            });
        }
        for(Thread t : threads){
            t.start();
            t.join();
        }
        System.out.println("OK");
    }
}
